package com.openjava.example.member.service;

import java.util.List;
import java.util.Map;
import java.util.Optional;
import javax.annotation.Resource;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.openjava.example.member.domain.ExampleMember;
import com.openjava.example.member.query.ExampleMemberDBParam;
import com.openjava.example.member.repository.ExampleMemberRepository;
/**
 * 业务层
 * @author 子右
 *
 */
@Service
@Transactional
public class ExampleMemberServiceImpl implements ExampleMemberService {
	
	@Resource
	private ExampleMemberRepository exampleMemberRepository;
	
	public Page<ExampleMember> query(ExampleMemberDBParam params, Pageable pageable){
		Page<ExampleMember> pageresult = exampleMemberRepository.query(params, pageable);
		return pageresult;
	}
	
	public List<ExampleMember> queryDataOnly(ExampleMemberDBParam params, Pageable pageable){
		return exampleMemberRepository.queryDataOnly(params, pageable);
	}
	
	public ExampleMember get(String id) {
		Optional<ExampleMember> o = exampleMemberRepository.findById(id);
		if(o.isPresent()) {
			ExampleMember m = o.get();
			return m;
		}
		System.out.println("找不到记录ExampleMember："+id);
		return null;
	}
	
	public ExampleMember doSave(ExampleMember m) {
		return exampleMemberRepository.save(m);
	}
	
	public void doDelete(String id) {
		exampleMemberRepository.deleteById(id);
	}
	public void doRemove(String ids) {
		String[] items = ids.split(",");
		for (int i = 0; i < items.length; i++) {
			exampleMemberRepository.deleteById(new String(items[i]));
		}
	}
}
